﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ex03.GarageLogic
{
    public class Wheel
    {
        private String m_WheelManufacturerName;
        private float m_WheelCurrentAirPressure;
        private float m_WheelMaximalAirPressureAllowed;

        public Wheel(float i_WheelMaximumAirPressureAllowed)
        {
            if (!isWheelMaximumAirPressureLegal(i_WheelMaximumAirPressureAllowed))
            {
                ValueOutOfRangeException WheelAirPressureError = new ValueOutOfRangeException();

                throw WheelAirPressureError;
            }
            else
            {
                m_WheelMaximalAirPressureAllowed = i_WheelMaximumAirPressureAllowed;
            }
        }
        
        public String WheelManufacturer
        {
            get { return m_WheelManufacturerName; }
            set 
            {
                if (value == null)
                {
                    ArgumentException WheelManufacturerNameError = new ArgumentException();

                    throw WheelManufacturerNameError;
                }
                else
                {
                    m_WheelManufacturerName = value;
                }
            }
        }

        public float WheelCurrentAirPressure
        {
            get { return m_WheelCurrentAirPressure; }
            set 
            {
                if (isWheelInputedAirPressureLegal(value))
                {
                    m_WheelCurrentAirPressure = value;
                }
                else
                {
                    ValueOutOfRangeException IllegalWheelAirPressure = new ValueOutOfRangeException();

                    throw IllegalWheelAirPressure;
                }
            }
        }

        public float WheelMaxAirPressureAllowed
        {
            get { return m_WheelMaximalAirPressureAllowed; }
        }

        public bool InflateWheel(float i_AirPressureToAdd)
        {
            bool ReturnValue = true;

            if ((m_WheelCurrentAirPressure + i_AirPressureToAdd) > m_WheelMaximalAirPressureAllowed)
            {
                ReturnValue = false;
            }
            else
            {
                m_WheelCurrentAirPressure += i_AirPressureToAdd;
            }

            return ReturnValue;
        }
        
        private bool isWheelMaximumAirPressureLegal(float i_CurrentWheelAirPressure)
        {
            bool ReturnValue = false;

            if (i_CurrentWheelAirPressure > 0F)
            {
                ReturnValue = true;
            }

            return ReturnValue;
        }

        private bool isWheelInputedAirPressureLegal(float i_WheelNewAirPressure)
        {
            bool ReturnValue = false;

            if (i_WheelNewAirPressure <= WheelMaxAirPressureAllowed)
            {
                ReturnValue = true;
            }

            return ReturnValue;
        }
    }
}
